@extends('layouts.admin')

@section('admin-content')
    <div class="box">
        @include('flash::message')
        <div class="box-header">
            <form action="{{url('user/search')}}" method="POST">
                <div class="col-xs-12 col-sm-8" style="padding-left: 0;margin-bottom: 10px;">
                    <div class="input-group">
                        <input type="text" name="search" class="form-control search-query"
                               placeholder="{{ trans("labels.user.name") }}/{{ trans("labels.user.email") }}" value="{{ $search }}" />
                        <span class="input-group-btn">
                            {{ csrf_field() }}
                            <button type="submit" class="btn btn-default btn-sm">
                                {{ trans("crud.search") }} <i class="glyphicon glyphicon-search"></i>
                            </button>
                        </span>
                    </div>
                </div>
            </form>
            <a class="btn btn-default btn-sm" href="{{url('user/create')}}">
                <i class="glyphicon glyphicon-pencil"></i>
                {{ trans("crud.create") }}
            </a>
        </div>
        <div class="box-body clearfix">
            <table class="table table-striped table-bordered table-hover">
                <tr>
                    <th>{{ trans("labels.user.name") }}</th>
                    <th>{{ trans("labels.user.email") }}</th>
                    <th>{{ trans("labels.user.role") }}</th>
                    <th>{{ trans("labels.user.status") }}</th>
                    <th>{{ trans("labels.action") }}</th>
                </tr>
                @foreach($paginator as $v)
                    <tr>
                        <td>{{$v->name}}</td>
                        <td>{{$v->email}}</td>
                        <td>{{ trans("strings.user.role.".$v->role) }}</td>
                        <td>{{ trans("strings.user.status.".$v->status) }}</td>
                        <td class="text-success">
                            <div class="action-buttons">
                                <a href="{{url("user/".$v->id."/edit")}}">
                                    <i class="glyphicon glyphicon-pencil"></i>
                                    {{ trans("crud.edit") }}
                                </a>
                                <a class="text-danger btn-delete" href="javascript:void(0)">
                                    <i class="glyphicon glyphicon-trash"></i>
                                    {{ trans("crud.destory") }}
                                    <form action="{{url('user/'.$v->id)}}" method="POST" class="delete_user" style="display:none">
                                        <input type="hidden" name="_method" value="delete">
                                        {{ csrf_field() }}
                                    </form>
                                </a>
                            </div>
                        </td>
                    </tr>
                @endforeach
            </table>
            {!! $paginator->render() !!}
        </div>
    </div>
@endsection

@section("admin-js")
    <script src="{{ asset('js/bootbox.js') }}"></script>
    <script type="text/javascript">
        $(function () {
            $('a.btn-delete').click(function() {
                var aobj = this;
                bootbox.confirm("{{ trans("alerts.deleteTitle") }}", function(result) {
                    if(result){
                        $(aobj).find(".delete_user").submit();
                    }
                });
            });
        })
    </script>
@endsection
